<?php

namespace api\modules\v1\models;
use Yii;
use api\common\models\Mar;
use api\common\models\Common;
use yii\web\HttpException;
use api\func\func;
use \yii\db\Query;
use yii\data\Pagination;
use yii\web\NotFoundHttpException;
class Publishpc extends Publish
{

    public function search($params){
        $type = intval($params['type']); //1 第三方用户 2 后台编辑
        $fields = 'id,title,url';
        $where = 'status = 99';
        $HtmlBaseUrl = self::getHtmlBaseUrl();
        if($type ==1 ){
            $uid = intval($params['uid']);
            $where .= ' and thirdid = '.$uid;
        }elseif($type == 2){
            $uid = ($params['uid']);
            $where .= " and username = '".$uid."'";
        }else{
            throw new HttpException(401,'类型参数错误',0);
        }

        $query = ((new Query())
            ->select($fields)
            ->from('{{%news}}')
            ->where($where)
        );
        /*$query->union((new Query())
            ->select($fields)
            ->from('{{%videos}} as a')
            //->leftJoin('{{%'.$value.'_data}} as b','a.id = b.id')
            ->where($where), true
        );*/
        $query->orderBy('inputtime desc')->limit(5);
        $data = $query->all();
        foreach ($data as $key => $value) {
            //静态html地址
            if ($value['url'] != '' && substr($value['url'], -5) == '.html') {
                $app_url = parse_url($value['url']);
                $app_url = $HtmlBaseUrl . $app_url['path'];
                //$app_url = str_replace('/html/', '/app/', $app_url);
                $data[$key]['url'] = $app_url;
            }
        }
        //print_r($data);exit;
        //echo $query->offset($pagination->offset)
        //->limit($pagination->limit)->createCommand()->getRawSql();exit;
        return $data;
    }
}
